<?php

// 活动取消报名
// DELETE activity.signOut

namespace app\api\resource\activity;
use think\Db;
use think\Session;

class SignOut
{
    // 方法
    public $_method = ['DELETE'];
    // 前置
    public $_pre    = ['login','isCyz'];
    // 描述
    public $_description = '活动取消报名';
    // 参数
    public $_param  = [
        'activity_id' => '活动主键',
    ];
    // 返回
    public $_return = [
        204 => '取消报名成功',
        400 => '项目不存在',
        422 => '请求参数不合法',
        500 => '服务器异常',
    ];

    public function run(&$request)
    {
        $activityId = $request->delete('activity_id/d',0);

        if (0 == $activityId) return [422,'活动主键必需'];

        $memberId = Session::get('member.id');

        $ret = Db::name('activity_signup')->where('activity_id',$activityId)->where('member_id',$memberId)->find();
        if ( is_null($ret) ) return [400,'项目不存在'];

        $num = Db::name('activity_signup')->where('activity_id',$activityId)->where('member_id',$memberId)->delete();

        return ($num > 0) ? [204,''] : 500;

    }
}